from view import View
from flask import Flask, jsonify, render_template

app = Flask(__name__)


@app.route('/')
def index():
    # 使用给定上下文，从模板文件夹呈现模板
    return render_template("index.html")


@app.route('/cpu_json', methods=['GET'])
def cpu_json():
    v = View()
    # 直接将CPU折线/面积图Line配置项目返回浏览器
    # 浏览器通过JavaScript代码再配置Line图
    return v.cpu_line_api()


@app.route('/memo_json', methods=['GET'])
def memo_json():
    v = View()
    c, val = v.memory_gauge_api()
    # 将以dict/json格式返回数据
    # jsonify(c_memo=v.memory_gauge_api())
    return jsonify({
        'c_memo': c,
        'stamp':val['stamp'],
        'total':val['total'],
        'used':val['used'],
        'available':val['available']
    })


if __name__ == '__main__':
    app.run(debug=True)
